import {Component, ViewChild} from '@angular/core';
import {Nav, Platform} from 'ionic-angular';
import {SplashScreen} from '@ionic-native/splash-screen';
import {StatusBar} from '@ionic-native/status-bar';
import {Badge} from '@ionic-native/badge';

import {HomePage} from '../pages/home/home';
import {NativePage} from '../pages/native/native';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: any = HomePage;

  static isCordova: boolean

  pages: Array<{ title: string, component: any }>;

  badgeNumber:any = 0;
  hasPermission:any;

  constructor(public platform: Platform,
              public badge: Badge,
              public statusBar: StatusBar,
              public splashScreen: SplashScreen) {
    this.initializeApp();

    // used for an example of ngFor and navigation
    this.pages = [
      {title: 'Home', component: HomePage},
      {title: 'Native', component: NativePage},
    ];


  }

  initializeApp() {
    this.platform.ready().then(() => {
      MyApp.isCordova = this.platform.is('cordova')
      this.statusBar.overlaysWebView(false)
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.splashScreen.hide();
      // this.badge.registerPermission();
      if(MyApp.isCordova){
        this.badge.hasPermission().then(()=>{
          this.badge.set(10);
        })
      }
    });
  }

  openPage(page) {
    // Reset the content nav to have just this page
    // we wouldn't want the back button to show in this scenario
    this.nav.setRoot(page.component);
  }
}
